package com.ifp.weixin.MessageMng.Dao.req.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.ifp.weixin.MessageMng.Dao.req.LocationMessageDao;
import com.ifp.weixin.MessageMng.Message.req.ReqLocationMessage;
@Service("locationMessageDao")
public class LocationMessageDaoImpl implements LocationMessageDao {

	private HibernateTemplate hibernateTemplate; 
	


	public List<ReqLocationMessage> getLocations() {
		// TODO Auto-generated method stub
		return (List<ReqLocationMessage>)this.hibernateTemplate.find("from LocationMessage");
	}

	public ReqLocationMessage loadById(long id) {
		// TODO Auto-generated method stub
		return this.hibernateTemplate.load(ReqLocationMessage.class, id);
	}

	public void save(ReqLocationMessage u) {
		// TODO Auto-generated method stub
		System.out.print("LocationMessageServiceImpl.save");
		hibernateTemplate.save(u);
	}


	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	public long getMaxIdFromUser( String FromUserName ){
		long  maxId = (Long) hibernateTemplate.getSessionFactory()
		.getCurrentSession().createQuery("select max(id) id from LocationMessage u where u.FromUserName = :FromUserName")
		.setString("FromUserName", FromUserName).uniqueResult();
		
		
		 return maxId;
	}	
}
